home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
machack
/
Hacks97
/
WarriorsProgress.sit
/
Warrior’s Progress
/
source code
/
Source
/
Libraries
/
Views
/
ViewMap.cp
< prev
next >
Wrap
Text File
|
1997-06-28
|
5KB
|
281 lines
// ViewMap.cp
#ifndef ViewMap_h
#include "ViewMap.h"
#endif
#ifndef WindowObject_h
#include "WindowObject.h"
#endif
#ifndef View_h
#include "View.h"
#endif
#ifndef Pane_h
#include "Pane.h"
#endif
const ViewMap *ViewMap::current = 0;
ViewMap::ViewMap( const View& view )
: previous( current )
{
current = this;
SetToVisible( view );
if ( visible )
{
clip -= Invalid( *window );
visible = !clip.IsEmpty();
visibleBounds = clip.Bounds();
}
Reassert();
}
ViewMap::ViewMap( const View& view, IncludeInvalid )
: previous( current )
{
current = this;
SetToVisible( view );
Reassert();
}
ViewMap::ViewMap( const View& view, InvalidOnly )
: previous( current )
{
current = this;
SetToVisible( view );
if ( visible )
{
clip &= Invalid( *window );
visible = !clip.IsEmpty();
visibleBounds = clip.Bounds();
}
Reassert();
}
ViewMap::ViewMap( const ViewMap& source )
: window( source.window ),
bounds( source.bounds ),
clip( source.clip ),
visible( source.visible ),
previous( current )
{
current = this;
if ( previous != &source )
Reassert();
}
void ViewMap::SetToVisible( const View& view )
{
if ( view.Mapped() )
{
const Pane& pane( view.Owner() );
window = &pane.Window();
if ( !Port().IsCurrent() )
Port().BeCurrent();
bounds = pane.Bounds();
clip = window->VisibleRegion();
pane.Clip( clip );
visible = !clip.IsEmpty();
visibleBounds = clip.Bounds();
}
else
{
window = 0;
bounds = Rectangle::zero;
visible = false;
}
}
ViewMap::~ViewMap()
{
Assert( current == this );
current = previous;
if ( current != 0 )
current->Reassert();
else
ClipRect( &Rectangle::big );
}
RegionObject& ViewMap::Invalid( const WindowObject& window )
{
static RegionObject invalid;
invalid = window.InvalidRegion();
invalid += window.Port().GlobalToLocal();
return invalid;
}
GrafPortObject& ViewMap::Port() const
{
Assert( window != 0 );
return window->Port();
}
void ViewMap::operator=( const ViewMap& source )
{
window = source.window;
bounds = source.bounds;
clip = source.clip;
visible = source.visible;
visibleBounds = source.visibleBounds;
if ( current == this )
Reassert();
}
void ViewMap::Set( const ViewMap& source, const Rectangle& restriction )
{
window = source.window;
bounds = restriction;
clip = source.clip;
clip &= restriction;
visible = source.visible && !clip.IsEmpty();
visibleBounds = clip.Bounds();
if ( current == this )
Reassert();
}
void ViewMap::Reassert() const
{
Assert( current == this );
if ( HasWindow() )
{
if ( !Port().IsCurrent() )
Port().BeCurrent();
SetClip( clip );
}
else
ClipRect( &Rectangle::zero );
}
void ViewMap::RestrictTo( const Rectangle& restriction )
{
clip &= restriction;
visibleBounds = clip.Bounds();
if ( clip.IsEmpty() )
visible = false;
if ( current == this )
SetClip( clip );
}
void ViewMap::RestrictTo( const RegionObject& restriction )
{
clip &= restriction;
visibleBounds = clip.Bounds();
if ( clip.IsEmpty() )
visible = false;
if ( current == this )
SetClip( clip );
}
void ViewMap::Validate() const
{
Assert( current == this );
if ( !Visible() )
return;
ValidRgn( clip );
}
void ViewMap::Validate( const Rectangle& r ) const
{
Assert( current == this );
if ( !Visible() )
return;
RegionObject region( r );
region &= clip;
ValidRgn( region );
}
void ViewMap::Validate( const RegionObject& r ) const
{
Assert( current == this );
if ( !Visible() )
return;
RegionObject region( r );
region &= clip;
ValidRgn( region );
}
void ViewMap::Invalidate() const
{
Assert( current == this );
if ( !Visible() )
return;
InvalRgn( clip );
}
void ViewMap::Invalidate( const Rectangle& r ) const
{
Assert( current == this );
if ( !Visible() )
return;
RegionObject region( r );
region &= clip;
InvalRgn( region );
}
void ViewMap::Invalidate( const RegionObject& r ) const
{
Assert( current == this );
if ( !Visible() )
return;
RegionObject region( r );
region &= clip;
InvalRgn( region );
}
void ViewMap::Erase() const
{
Assert( current == this );
if ( !Visible() )
return;
EraseRect( &bounds );
}
void ViewMap::Erase( const Rectangle& r ) const
{
Assert( current == this );
if ( !Visible() )
return;
EraseRect( &r );
}
void ViewMap::Erase( const RegionObject& r ) const
{
Assert( current == this );
if ( !Visible() )
return;
EraseRgn( r );
}